package com.taovr.core.web;

import com.taovr.password.DefaultPasswordEncoder;
import com.taovr.password.PasswordEncoder;

/**
 * 加密解密算法
 */
public class CryptoUtil {

	/**
	 * 加密算法
	 */
	public static String encryption(String encStr) {
		PasswordEncoder passwordEncoder = DefaultPasswordEncoder.getDefaultInstance();
		return passwordEncoder.encodePassword(encStr);
	}

	public static boolean isValid(String pwd1, String pwd2) {
		PasswordEncoder passwordEncoder = DefaultPasswordEncoder.getDefaultInstance();
		return passwordEncoder.isValidPassword(pwd1, pwd2);
	}

	/**
	 * 解密算法
	 */
	public static String Decrypt(String deccStr) {
		throw new RuntimeException("Not supported yet");
	}
	public static void main(String[] args) {
		boolean flag = isValid("123456", "{PKCS5S2}m/a7RW+hNxjhwjT5bLrZDBxMTx0Dhg/SKRm5Ot6o/ouyr4a2npSOaQtLAYx9+PuT");
		System.out.println(flag);

		PasswordEncoder passwordEncoder = DefaultPasswordEncoder.getDefaultInstance();
		String pass1 = "liqiang";
		String pass2 = "{PKCS5S2}jUDxQ/O4KTAF9r9PQ0tSWO6TJDS6l3pocLr1qSSddOK7ec0lzkIEJ046XOFVyHuZ";
		System.out.println(passwordEncoder.isValidPassword(pass1, pass2));
		System.out.println(passwordEncoder.encodePassword(pass1));
		System.out.println(passwordEncoder.isValidPassword(pass1, passwordEncoder.encodePassword(pass1)));
		System.out.println(passwordEncoder.encodePassword("123456"));
		System.out.println(passwordEncoder.isValidPassword("123456", passwordEncoder.encodePassword("123456")));
		String x1 = "{PKCS5S2}m3hfdKG8VrUmOWx+YsdjSL/z1+kNwh/1zL1sCtCLBOe/A78r86oL+lLNfl+6rXhX";
		String x2 = "{PKCS5S2}etAsyGeWFIpSs1otfnbjhIuxw3XRa+hrtFs6MuxVs6BHJ2pN5e4S+9kJT+VNsL9d";
		String x3 = "{PKCS5S2}Z4+mTnWEt/Mbx+JY8Yv33Ed5XDYwoqnZurUwzUadIm2eUThtIPU4jNP5dV8qddzw";
		System.out.println();
		System.out.println(passwordEncoder.canDecodePassword(x1));
		System.out.println(passwordEncoder.canDecodePassword(x2));
		System.out.println(passwordEncoder.canDecodePassword(x3));
	}
}
